package utils

func Contains[T comparable](l []T, findFunc findFunc[T]) bool {
	for _, other := range l {
		if findFunc(other) {
			return true
		}
	}
	return false
}

func IndexOf[T comparable](l []T, item T) int {
	for i, other := range l {
		if other == item {
			return i
		}
	}
	return -1
}

func Remove[T comparable](l []T, item T) []T {
	for i, other := range l {
		if other == item {
			return append(l[:i], l[i+1:]...)
		}
	}
	return l
}

func Find[T comparable](l []T, findFunc findFunc[T]) *T {
	for _, other := range l {
		if findFunc(other) {
			return &other
		}
	}
	return nil
}

type findFunc[T comparable] func(t T) bool
